package com.learning.javaweb_springboot_page_query.controller;

import com.learning.javaweb_springboot_page_query.entity.Order;
import com.learning.javaweb_springboot_page_query.entity.User;
import com.learning.javaweb_springboot_page_query.mapper.OrderMapper;
import com.learning.javaweb_springboot_page_query.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class OrderController {

    @Autowired
    OrderMapper orderMapper;

    @Autowired
    OrderService orderService;

    //多表查询，查询所有订单，包括其对应用户
    @GetMapping("/order/findAll1")
    public List findAll(){
        List orders=orderMapper.selectALLOrdersAndUser();
        return orders;
    }

    // 单表查询，通过uid获取订单列表的API接口
    @GetMapping("/order/{uid}")
    public List<Order> getOrdersByUid(@PathVariable int uid) {
        return orderService.getOrdersByUid(uid);
    }

    // 单表查询，根据ID查询
    @GetMapping("/orders/{id}")
    public Order queryOrderById(@PathVariable Integer id) {
        return orderService.queryOrderById(id);

    }
}
